package com.liangzhong.view.tips
{
	import com.common.utils.Reflection;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.goods.vo.GoodsVo;
	import com.liangzhong.model.goods.vo.PlayerStarVo;
	import com.liangzhong.model.task.vo.TaskInfoVo;
	import com.liangzhong.model.type.GoodsType;
	
	import flash.display.Bitmap;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.text.TextField;
	
	import lz.controls.tips.ITip;

	/**
	 *任务 
	 * @author Administrator
	 * 
	 */	
	public class TaskTips extends Sprite implements ITip
	{
		private var _skin:MovieClip;
		/**
		 * 
		 */
		private var contain:MovieClip;
		/**
		 *奖励 
		 */
		private var award:TextField;
		/**
		 * 
		 */
		private var _bg:MovieClip;
		public function TaskTips()
		{
			super();
			initUI();
		}
		public function initUI():void
		{
			_skin = Reflection.createInstance("com.lz.modul.task.Tips");
			this.addChild(_skin);
			_bg = _skin.taskTipsBg;
			contain = _skin.contain;
			award = _skin.award;
			award.text = "";
		}
		
		public function get data():Object
		{
			return null;
		}
		
		public function set data(value:Object):void
		{
			var vo:TaskInfoVo = value as TaskInfoVo;
			if(vo == null)return;
			var str:String = "";
			if(vo.coin > 0)
				str = "欧元：" + vo.coin + "\n";
			if(vo.exp > 0)
				str += "经验：" + vo.exp + "\n";
			if(vo.fame > 0)
				str += "声望：" + vo.fame;
			award.text = str;
			
			var bitmap:Bitmap;
			
			//球员背景
			var playerBg:MovieClip;
			var goods:GoodsVo;
			
			goods= AppData.getInstance().goodsManager.getGoodsByTypeAndId(vo.ntype1,vo.pid1);
			
			if(goods != null)
			{
//				bitmap = new Bitmap(goods.bitmapData);
//				if(goods is PlayerStarVo)
//				{
//					playerBg = Reflection.createInstance("com.lz.res.PlayerColorBg");
//					contain.addChild(playerBg);
//					playerBg.x = bitmap.x -1;
//					playerBg.y = bitmap.y +1;
//				}
//				bitmap.x = (bitmap.width + 3)* contain.numChildren;
//				contain.addChild(bitmap);
				creatItem(goods);
			}
			goods =null;
			goods= AppData.getInstance().goodsManager.getGoodsByTypeAndId(vo.ntype2,vo.pid2);
			if(goods != null)
			{
//				bitmap = new Bitmap(goods.bitmapData);
//				bitmap.x = (bitmap.width + 3)* Math.ceil(contain.numChildren /2);
//				if(goods is PlayerStarVo)
//				{
//					playerBg = Reflection.createInstance("com.lz.res.PlayerColorBg");
//					contain.addChild(playerBg);
//					playerBg.x = bitmap.x -1;
//					playerBg.y = bitmap.y +1;
//				}
//				
//				contain.addChild(bitmap);
				creatItem(goods);
			}
			goods =null;
			goods= AppData.getInstance().goodsManager.getGoodsByTypeAndId(vo.ntype3,vo.pid3);
			if(goods != null)
			{
//				bitmap = new Bitmap(goods.bitmapData);
//				bitmap.x = (bitmap.width + 3)*Math.ceil(contain.numChildren /2);
//				if(goods is PlayerStarVo)
//				{
//					playerBg = Reflection.createInstance("com.lz.res.PlayerColorBg");
//					contain.addChild(playerBg);
//					playerBg.x = bitmap.x -1;
//					playerBg.y = bitmap.y +1;
//				}
//				contain.addChild(bitmap);
				creatItem(goods);
			}
			
			_bg.width = award.x + award.width + contain.width + 10;
		}
		
		/**
		 * 
		 * 
		 */
		private function creatItem($goods:GoodsVo):void
		{
			var sp:Sprite = new Sprite();
			var container:MovieClip ;
			var mc:MovieClip = Reflection.createInstance("com.liangzhong.ui.res.PropBg");
			mc.bg.width = 54;
			mc.bg.height = 55;
			mc.x = 0;
			mc.y = 0;
			container = mc.container;
			sp.addChild(mc);
			var bitmap:Bitmap;
			bitmap = new Bitmap($goods.bitmapData);
			var colorBg		:MovieClip;
			if($goods.type == GoodsType.PLAYERCARD)
			{
				colorBg = Reflection.createInstance("com.lz.res.PlayerColorBg");
				container.addChild(colorBg);
				colorBg.y = 0;
				colorBg.x = 1;
				colorBg.gotoAndStop($goods.color);
			}
			container.addChild(bitmap);
//			bitmap.x = 2;
			sp.x = (sp.width + 3)* contain.numChildren;
			contain.addChild(sp);
			container.x = 2;
			container.y = 2.35;
		}
		
		public function destroy():void
		{
		}
	}
}